home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / ADA / GNAT / !gcc / adainc / 6 / ads / s-taskin < prev    next >
Text File  |  1996-02-12  |  31KB  |  748 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                 GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS               --
  4. --                                                                          --
  5. --                        S Y S T E M . T A S K I N G                       --
  6. --                                                                          --
  7. --                                  S p e c                                 --
  8. --                           (Compiler Interface)                           --
  9. --                                                                          --
  10. --                             $Revision: 1.42 $                            --
  11. --                                                                          --
  12. --    Copyright (C) 1991, 92, 93, 94, 1995 Free Software Foundation, Inc.   --
  13. --                                                                          --
  14. -- GNARL is free software; you can  redistribute it  and/or modify it under --
  15. -- terms of the  GNU General Public License as published  by the Free Soft- --
  16. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  17. -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
  18. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  19. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  20. -- for  more details.  You should have  received  a copy of the GNU General --
  21. -- Public License  distributed with GNARL; see file COPYING.  If not, write --
  22. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  23. -- MA 02111-1307, USA.                                                      --
  24. --                                                                          --
  25. -- As a special exception,  if other files  instantiate  generics from this --
  26. -- unit, or you link  this unit with other files  to produce an executable, --
  27. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  28. -- covered  by the  GNU  General  Public  License.  This exception does not --
  29. -- however invalidate  any other reasons why  the executable file  might be --
  30. -- covered by the  GNU Public License.                                      --
  31. --                                                                          --
  32. -- GNARL was developed by the GNARL team at Florida State University. It is --
  33. -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
  34. -- State University (http://www.gnat.com).                                  --
  35. --                                                                          --
  36. ------------------------------------------------------------------------------
  37.  
  38. --  This package provides necessary type definitions for compiler interface.
  39.  
  40. --  Note: the compiler generates direct calls to this interface, via Rtsfind.
  41. --  Any changes to this interface may require corresponding compiler changes.
  42.  
  43. with Ada.Finalization;
  44.  
  45. with Ada.Exceptions;
  46. --  Used for:  Exception_Id
  47.  
  48. with System.Parameters;
  49. --  Used for:  Size_Type
  50.  
  51. with System.Task_Primitives;
  52. --  Used for:  Task_Primitives.Lock
  53.  
  54. with System.Task_Specific_Data;
  55. --  Used for: TSD
  56.  
  57. with System.Task_Info;
  58. --  Used for: Task_Info_Type;
  59.  
  60. package System.Tasking is
  61.  
  62.    ---------------------------------
  63.    -- Task_ID related definitions --
  64.    ---------------------------------
  65.  
  66.    type Ada_Task_Control_Block;
  67.  
  68.    type Task_ID is access Ada_Task_Control_Block;
  69.    --  This should be a private type. However, compiler generates internal
  70.    --  while compiling s-taprob.adb
  71.  
  72.    Null_Task : constant Task_ID;
  73.  
  74.    type Task_List is array (Positive range <>) of Task_ID;
  75.  
  76.    function Self return Task_ID;
  77.    pragma Inline (Self);
  78.  
  79.    -----------------------------------
  80.    -- Master_ID Related Definitions --
  81.    -----------------------------------
  82.  
  83.    type Master_ID is private;
  84.  
  85.    ---------------------------
  86.    -- Priority Declarations --
  87.    ---------------------------
  88.  
  89.    Unspecified_Priority : constant Integer := System.Priority'First - 1;
  90.  
  91.    Priority_Not_Boosted : constant Integer := System.Priority'First - 1;
  92.  
  93.    subtype Rendezvous_Priority is Integer
  94.      range Priority_Not_Boosted .. System.Any_Priority'Last;
  95.  
  96.    -----------------------
  97.    -- Enumeration types --
  98.    -----------------------
  99.  
  100.    type Task_Stage is (
  101.       Created,
  102.       --  Task has been created but has not begun activation.
  103.  
  104.       Can_Activate,
  105.       --  Task has begin activation.
  106.  
  107.       Active,
  108.       --  Task has completed activation and is executing the task body.
  109.  
  110.       Await_Dependents,
  111.       --  Task is trying to complete a task master other than itself,
  112.       --  and is waiting for the tasks dependent on that master to become
  113.       --  passive (be complete, terminated, or be waiting on a terminate
  114.       --  alternative).
  115.  
  116.       Passive,
  117.       --  The task is passive.
  118.  
  119.       Completing,
  120.       --  The task is committed to becoming complete, but has not yet
  121.       --  satisfied all of the conditions for completion. This
  122.       --  acts as a claim to completion; once Stage is set to this value,
  123.       --  no other task can continue with completion.
  124.  
  125.       Complete,
  126.       --  The task is complete. The task and all of its dependents are
  127.       --  passive; some dependents may still be waiting on terminate
  128.       --  alternatives.
  129.  
  130.       Terminated);
  131.       --  The task is terminated. All dependents waiting on terminate
  132.       --  alternatives have been awakened and have terminated themselves.
  133.  
  134.    type Accepting_State is (
  135.       Not_Accepting,   --  task is not ready to accept any entry call
  136.       Trivial_Accept,   --  "accept E;"
  137.       Simple_Accept,    --  "accept E do ... end E;"
  138.       Select_Wait);     --  most general case
  139.  
  140.    type Call_Modes is (Simple_Call, Conditional_Call, Asynchronous_Call);
  141.  
  142.    type Select_Modes is (Simple_Mode, Else_Mode, Terminate_Mode, Delay_Mode);
  143.  
  144.    -----------------------------------
  145.    -- ATC_Level related definitions --
  146.    -----------------------------------
  147.  
  148.    Max_ATC_Nesting : constant Natural := 20;
  149.  
  150.    subtype ATC_Level_Base is Integer range 0 .. Max_ATC_Nesting;
  151.  
  152.    ATC_Level_Infinity : constant ATC_Level_Base := ATC_Level_Base'Last;
  153.  
  154.    subtype ATC_Level is ATC_Level_Base range
  155.      ATC_Level_Base'First .. ATC_Level_Base'Last - 1;
  156.  
  157.    subtype ATC_Level_Index is ATC_Level
  158.      range ATC_Level'First + 1 .. ATC_Level'Last;
  159.  
  160.    -------------------------------
  161.    -- Entry related definitions --
  162.    -------------------------------
  163.  
  164.    Null_Entry : constant := 0;
  165.  
  166.    Max_Entry : constant := Integer'Last;
  167.  
  168.    Interrupt_Entry : constant := -2;
  169.  
  170.    Cancelled_Entry : constant := -1;
  171.  
  172.    type Entry_Index is range Interrupt_Entry .. Max_Entry;
  173.  
  174.    type Entry_Call_Record;
  175.  
  176.    type Entry_Call_Link is access all Entry_Call_Record;
  177.  
  178.    type Entry_Queue is record
  179.       Head : Entry_Call_Link;
  180.       Tail : Entry_Call_Link;
  181.    end record;
  182.  
  183.    ----------------------------
  184.    -- PO related definitions --
  185.    ----------------------------
  186.  
  187.    Null_Protected_Entry : constant := Null_Entry;
  188.  
  189.    Max_Protected_Entry : constant := Max_Entry;
  190.  
  191.    type Protected_Entry_Index is new Entry_Index
  192.      range Null_Protected_Entry .. Max_Protected_Entry;
  193.  
  194.    subtype Positive_Protected_Entry_Index is
  195.      Protected_Entry_Index range  1 .. Protected_Entry_Index'Last;
  196.  
  197.    type Protection (Num_Entries : Protected_Entry_Index) is private;
  198.    --  This type contains the GNARL state of a protected object. The
  199.    --  application-defined portion of the state (i.e. private objects)
  200.    --  is maintained by the compiler-generated code.
  201.  
  202.    type Protection_Access is access all Protection;
  203.  
  204.    Null_PO : constant Protection_Access := null;
  205.  
  206.    type Communication_Block is private;
  207.    --  Objects of this type are passed between GNARL calls to allow RTS
  208.    --  information to be preserved.
  209.  
  210.    ------------------------------------
  211.    -- Rendezvous related definitions --
  212.    ------------------------------------
  213.  
  214.    Null_Task_Entry : constant := Null_Entry;
  215.  
  216.    Max_Task_Entry : constant := Max_Entry;
  217.  
  218.    type Task_Entry_Index is new Entry_Index
  219.      range Null_Task_Entry .. Max_Task_Entry;
  220.  
  221.    type Task_Entry_Queue_Array is
  222.      array (Task_Entry_Index range <>) of
  223.      Entry_Queue;
  224.  
  225.    No_Rendezvous : constant := 0;
  226.  
  227.    Max_Select : constant Integer := Integer'Last;
  228.    --  RTS-defined
  229.  
  230.    subtype Select_Index is Integer range No_Rendezvous .. Max_Select;
  231.    --   type Select_Index is range No_Rendezvous .. Max_Select;
  232.  
  233.    subtype Positive_Select_Index is
  234.      Select_Index range 1 .. Select_Index'Last;
  235.  
  236.    type Accept_Alternative is record --  should be packed
  237.       Null_Body : Boolean;
  238.       S : Task_Entry_Index;
  239.    end record;
  240.  
  241.    type Accept_List is
  242.      array (Positive_Select_Index range <>) of Accept_Alternative;
  243.  
  244.    type Accept_List_Access is access constant Accept_List;
  245.  
  246.    ----------------------------------
  247.    -- Entry_Call_Record definition --
  248.    ----------------------------------
  249.  
  250.    type Entry_Call_Record is record
  251.  
  252.       Prev : Entry_Call_Link;
  253.       Next : Entry_Call_Link;
  254.  
  255.       Self  : Task_ID;
  256.       Level : ATC_Level;
  257.       --  One of Self and Level are redundant in this implementation, since
  258.       --  each Entry_Call_Record is at Self.Entry_Calls (Level). Since we must
  259.       --  have access to the entry call record to be reading this, we could
  260.       --  get Self from Level, or Level from Self. However, this requires
  261.       --  non-portable address arithmetic.
  262.  
  263.       Mode : Call_Modes;
  264.  
  265.       Abortable : Boolean;
  266.       --  This call is queued abortably.
  267.       --  Protection: Acceptor.L. If the call is not on a queue, it should
  268.       --  only be accessed by the task doing the call or requeue, and the
  269.       --  mutex need not be locked in those cases.
  270.  
  271.       Done : Boolean;
  272.       --  The call has been completed.
  273.       --  Protection : Self.L, except in certain circumstances where
  274.       --  Self knows that the acceptor is suspended waiting for a call,
  275.       --  and Self holds the acceptor's mutex.
  276.  
  277.       Has_Been_Abortable : Boolean;
  278.       --  The call has been blocked abortably at some point.
  279.       --  Currently only used for protected entry calls.
  280.       --  Protection: Called_PO.L.
  281.  
  282.       E : Entry_Index;
  283.  
  284.       Prio : System.Any_Priority;
  285.  
  286.       --  The above fields are those that there may be some hope of packing.
  287.       --  They are gathered together to allow for compilers that lay records
  288.       --  out contiguously, to allow for such packing.
  289.  
  290.       Uninterpreted_Data : System.Address;
  291.  
  292.       Exception_To_Raise : Ada.Exceptions.Exception_Id;
  293.       --  The exception to raise once this call has been completed without
  294.       --  being aborted.
  295.  
  296.       --  Server : Server_Record;
  297.  
  298.       Called_Task : Task_ID;
  299.       --  For task entry calls only. Only one of Called_Task and Called_PO
  300.       --  are valid; the other must be Null_Task or null, respectively.
  301.       --  In general, Called_Task must be either a legitimate Task_ID or
  302.       --  Null_Task.  Both Called_Task and Called_PO must be null
  303.       --  if the call record is not in use.
  304.       --  Protection:  Called_Task.L. There are situations in which
  305.       --  it is necessary to access this field given only an Entry_Call_Record.
  306.       --  This is difficult, since Called_Task.L must be locked to access
  307.       --  Called_Task. This is done by doing the lock and then checking
  308.       --  to make sure that Called_Task has not changed; see
  309.       --  System.Tasking.Utilities.Lock_Server.
  310.  
  311.       Acceptor_Prev_Call : Entry_Call_Link;
  312.       --  For task entry calls only.
  313.  
  314.       Acceptor_Prev_Priority : Rendezvous_Priority := Priority_Not_Boosted;
  315.       --  For task entry calls only.
  316.       --  The priority of the most recent prior call being serviced.
  317.       --  For protected entry calls, this function should be performed by
  318.       --  GNULLI ceiling locking.
  319.  
  320.       Called_PO : Protection_Access;
  321.       --  For protected entry calls only. Only one of Called_Task and
  322.       --  Called_PO are valid; the other must be Null_Task or Null_PO,
  323.       --  respectively. In general, Called_PO must be either a legitimate
  324.       --  Protection_Access value or null.  Both Called_Task and
  325.       --  Called_PO must be null if the call record is not in use.
  326.       --  Protection: Called_PO.L. See notes under Called_Task, above.
  327.  
  328.    end record;
  329.  
  330.    ------------------------------------
  331.    -- Task related other definitions --
  332.    ------------------------------------
  333.  
  334.    type Activation_Chain is limited private;
  335.  
  336.    type Activation_Chain_Access is access all Activation_Chain;
  337.  
  338.    type Task_Procedure_Access is access procedure (Arg : System.Address);
  339.  
  340.    type Access_Boolean is access all Boolean;
  341.  
  342.    type Access_Address is access all System.Address;
  343.  
  344.    ----------------------------------------------
  345.    -- Ada_Task_Control_Block (ATCB) definition --
  346.    ----------------------------------------------
  347.  
  348.    type Entry_Call_Array is array (ATC_Level_Index) of
  349.      aliased Entry_Call_Record;
  350.  
  351.    D_I_Count : constant := 2;
  352.    --  This constant may be adjusted, to allow more Address-sized
  353.    --  attributes to be stored directly in the task control block.
  354.  
  355.    subtype Direct_Index is Integer range 0 .. D_I_Count - 1;
  356.    --  Attributes with indices in this range are stored directly in
  357.    --  the task control block.  Such attributes must be Address-sized.
  358.    --  Other attributes will be held in dynamically allocated records
  359.    --  chained off of the task control block.
  360.  
  361.    type Direct_Attribute_Array is
  362.      array (0 .. D_I_Count - 1) of aliased System.Address;
  363.  
  364.    type Direct_Index_Vector is mod 2 ** D_I_Count;
  365.    --  This is a bit-vector type, used to store information about
  366.    --  the usage of the direct attribute fields.
  367.  
  368.    --  Notes on protection (synchronization) of TRTS data structures.
  369.  
  370.    --  Any field of the TCB can be written by the activator of a task when the
  371.    --  task is created, since no other task can access the new task's
  372.    --  state until creation is complete.
  373.  
  374.    --  The protection for each field is described in a comment starting with
  375.    --  "Protection:".
  376.  
  377.    --  When a lock is used to protect an ATCB field, this lock is simply named.
  378.  
  379.    --  Some protection is described in terms of tasks related to the
  380.    --  ATCB being protected. These are:
  381.  
  382.    --    Self: The task which is controlled by this ATCB.
  383.    --    Acceptor: A task accepting a call from Self.
  384.    --    Caller: A task calling an entry of Self.
  385.    --    Parent: The task executing the master on which Self depends.
  386.    --    Dependent: A task dependent on Self.
  387.    --    Activator: The task that created Self and initiated its activation.
  388.    --    Created: A task created and activated by Self.
  389.  
  390.    type Ada_Task_Control_Block (Entry_Num : Task_Entry_Index) is record
  391.  
  392.       LL_TCB : aliased System.Task_Primitives.Task_Control_Block;
  393.       --  Control block used by the underlying low-level tasking service
  394.       --  (GNULLI).
  395.       --  Protection: This is used only by the GNULLI implementation, which
  396.       --  takes care of all of its synchronization.
  397.  
  398.       Task_Entry_Point : Task_Procedure_Access;
  399.       --  Information needed to call the procedure containing the code for
  400.       --  the body of this task.
  401.       --  Protection: Part of the synchronization between Self and
  402.       --  Activator. Activator writes it, once, before Self starts
  403.       --  executing. Self reads it, once, as part of its execution.
  404.  
  405.       Task_Arg : System.Address;
  406.       --  The argument to to task procedure. Currently unused; this will
  407.       --  provide a handle for discriminant information.
  408.       --  Protection: Part of the synchronization between Self and
  409.       --  Activator. Activator writes it, once, before Self starts
  410.       --  executing. Thereafter, Self only reads it.
  411.  
  412.       Task_Info : System.Task_Info.Task_Info_Type;
  413.       --  System-specific attributes of the task as specified by the
  414.       --  Task_Info pragma.
  415.  
  416.       Stack_Size : System.Parameters.Size_Type;
  417.       --  Requested stack size.
  418.       --  Protection: Only used by Self.
  419.  
  420.       Current_Priority : System.Any_Priority;
  421.       --  Active priority, except that the effects of protected object
  422.       --  priority ceilings are not reflected. This only reflects explicit
  423.       --  priority changes and priority inherited through task activation
  424.       --  and rendezvous.
  425.       --  Ada 95 notes: In Ada 95, this field will be transferred to the
  426.       --  Priority field of an Entry_Calls component when an entry call
  427.       --  is initiated. The Priority of the Entry_Calls component will not
  428.       --  change for the duration of the call. The accepting task can
  429.       --  use it to boost its own priority without fear of its changing in
  430.       --  the meantime.
  431.       --  This can safely be used in the priority ordering
  432.       --  of entry queues. Once a call is queued, its priority does not
  433.       --  change.
  434.       --  Since an entry call cannot be made while executing
  435.       --  a protected action, the priority of a task will never reflect a
  436.       --  priority ceiling change at the point of an entry call.
  437.       --  Protection: Only written by Self, and only accessed when Acceptor
  438.       --  accepts an entry or when Created activates, at which points Self is
  439.       --  suspended.
  440.  
  441.       Base_Priority : System.Any_Priority;
  442.       --  Base priority, not changed during entry calls, only changed
  443.       --  via dynamic priorities package.
  444.       --  Protection: Only written by Self, accessed by anyone.
  445.  
  446.       New_Base_Priority : System.Any_Priority;
  447.       --  New value for Base_Priority (for dynamic priorities package).
  448.       --  Protection: Self.L.
  449.  
  450.       L : System.Task_Primitives.Lock;
  451.       --  General purpose lock; protects most fields in the ATCB.
  452.  
  453.       Compiler_Data : System.Task_Specific_Data.TSD;
  454.       --  Task-specific data needed by the compiler to store
  455.       --  per-task structures.
  456.       --  Protection: Only accessed by Self.
  457.  
  458.       --  the following declarations are for Rendezvous
  459.  
  460.       Cond : System.Task_Primitives.Condition_Variable;
  461.       --  Used by Self to wait for a condition to become true.
  462.       --  It is invariant in the GNARL that a task waits only on its
  463.       --  own condition variable.
  464.       --  Protection: Condition variables are always associated with a lock.
  465.       --  The runtime places no restrictions on which lock is used, except
  466.       --  that it must protection the condition upon which the task is waiting.
  467.  
  468.       All_Tasks_Link : Task_ID;
  469.       --  Used to link this task to the list of all tasks in the system.
  470.       --  Protection: All_Tasks.L.
  471.  
  472.       Global_Task_Lock_Nesting : Natural;
  473.       --  This is the current nesting level of calls to
  474.       --  System.Tasking.Stages.Lock_Task_T.
  475.       --  This allows a task to call Lock_Task_T multiple times without
  476.       --  deadlocking. A task only locks All_Task_Lock when its
  477.       --  All_Tasks_Nesting goes from 0 to 1, and only unlocked when it
  478.       --  goes from 1 to 0.
  479.       --  Protection: Only accessed by Self.
  480.  
  481.       Activation_Link : Task_ID;
  482.       --  Used to link this task to a list of tasks to be activated.
  483.       --  Protection: Only used by Activator.
  484.  
  485.       Open_Accepts : Accept_List_Access;
  486.       --  This points to the Open_Accepts array of accept alternatives passed
  487.       --  to the RTS by the compiler-generated code to Selective_Wait.
  488.       --  Protection: Self.L.
  489.  
  490.       Exception_To_Raise : Ada.Exceptions.Exception_Id;
  491.       --  An exception which should be raised by this task when it regains
  492.       --  control.
  493.       --  Protection: Read only by Self, under circumstances where it will
  494.       --  be notified by the writer when it is safe to read it:
  495.       --  1. Written by Acceptor, when Self is suspended.
  496.       --  2. Written by Notify_Exception, executed by Self through a
  497.       --     synchronous signal handler, which redirects control to a
  498.       --     routine to read it and raise the exception.
  499.  
  500.       Chosen_Index : Select_Index;
  501.       --  The index in Open_Accepts of the entry call accepted by a selective
  502.       --  wait executed by this task.
  503.       --  Protection: Written by both Self and Caller. Usually protected
  504.       --  by Self.L. However, once the selection is known to have been
  505.       --  written it can be accessed without protection. This happens
  506.       --  after Self has updated it itself using information from a suspended
  507.       --  Caller, or after Caller has updated it and awakened Self.
  508.  
  509.       Call : Entry_Call_Link;
  510.       --  The entry call that has been accepted by this task.
  511.       --  Protection: Self.L. Self will modify this field
  512.       --  when Self.Accepting is False, and will not need the mutex to do so.
  513.       --  Once a task sets Stage=Completing, no other task can access this
  514.       --  field.
  515.  
  516.       --  The following fields are used to manage the task's life cycle.
  517.  
  518.       Aborter_Link : Task_ID;
  519.       --  Link to the list of tasks which tries to abort this task but
  520.       --  blocked by another aborter who has already been aborting the task.
  521.  
  522.       Activator : Task_ID;
  523.       --  The task that created this task, either by declaring it as a task
  524.       --  object or by executing a task allocator.
  525.       --  Protection: Set by Activator before Self is activated, and
  526.       --  read after Self is activated.
  527.  
  528.       Parent : Task_ID;
  529.       Master_of_Task : Master_ID;
  530.       --  The task executing the master of this task, and the ID of this task's
  531.       --  master (unique only among masters currently active within Parent).
  532.       --  Protection: Set by Activator before Self is activated, and
  533.       --  read after Self is activated.
  534.  
  535.       Master_Within : Master_ID;
  536.       --  The ID of the master currently executing within this task; that is,
  537.       --  the most deeply nested currently active master.
  538.       --  Protection: Only written by Self, and only read by Self or by
  539.       --  dependents when Self is attempting to exit a master. Since Self
  540.       --  will not write this field until the master is complete, the
  541.       --  synchronization should be adequate to prevent races.
  542.  
  543.       Activation_Count : Integer;
  544.       --  This is the number of tasks that this task is activating, i.e. the
  545.       --  children that have started activation but have not completed it.
  546.       --  Protection: Self.L and Created.L. Both mutexes must be locked,
  547.       --  since Self.Activation_Count and Created.Stage must be synchronized.
  548.  
  549.       Awake_Count : Integer;
  550.       --  Number of tasks dependent on this task (including this task) that are
  551.       --  still "awake": not terminated and not waiting on a terminate
  552.       --  alternative.
  553.       --  Protection: Self.L. Parent.L must also be locked when this is
  554.       --  updated, so that it can be synchronized with
  555.       --  Parent.Awaited_Dependent_Count, except under special circumstances
  556.       --  where we know that the two can be out of sync without allowing the
  557.       --  parent to terminate before its dependents.
  558.  
  559.       Awaited_Dependent_Count : Integer;
  560.       --  This is the awake count of a master being completed by this task.
  561.       --  Protection: Self.L. Dependent.L must also be locked so that
  562.       --  this field and Dependent.Awake_Count can be synchronized, except
  563.       --  under special circumstances where we know that the two can be out
  564.       --  of sync without allowing the parent to terminate before its
  565.       --  dependents.
  566.  
  567.       Terminating_Dependent_Count : Integer;
  568.       --  This is the count of tasks dependent on a master being completed by
  569.       --  this task which are waiting on a terminate alternative. Only valid
  570.       --  when there none of the dependents are awake.
  571.       --  Protection: Self.L.
  572.  
  573.       Pending_Priority_Change : Boolean;
  574.       --  Flag to indicate pending priority change (for dynamic priorities
  575.       --  package). The base priority is updated on the next abortion
  576.       --  completion point (aka. synchronization point).
  577.       --  Protection: Self.L.
  578.  
  579.       Pending_Action : Boolean;
  580.       --  Unified flag indicating pending action on abortion completion
  581.       --  point (aka. synchronization point). Currently set if:
  582.       --  . Pending_Priority_Change is set or
  583.       --  . Pending_ATC_Level is changed.
  584.       --  Protection: Self.L.
  585.  
  586.       Pending_ATC_Level : ATC_Level_Base;
  587.       --  The ATC level to which this task is currently being aborted.
  588.       --  Protection: Self.L.
  589.  
  590.       ATC_Nesting_Level : ATC_Level;
  591.       --  The dynamic level of ATC nesting (currently executing nested
  592.       --  asynchronous select statements) in this task.
  593.       --  Protection: This is only used by Self. However, decrementing it
  594.       --  in effect deallocates an Entry_Calls component, and care must be
  595.       --  taken that all references to that component are eliminated before
  596.       --  doing the decrement. This in turn will probably required locking
  597.       --  a protected object (for a protected entry call) or the Acceptor's
  598.       --  lock (for a task entry call). However, ATC_Nesting_Level itself can
  599.       --  be accessed without a lock.
  600.  
  601.       Deferral_Level : Natural;
  602.       --  This is the number of times that Defer_Abortion has been called by
  603.       --  this task without a matching Undefer_Abortion call. Abortion is
  604.       --  only allowed when this zero.
  605.       --  Protection: Only updated by Self; access assumed to be atomic.
  606.  
  607.       Elaborated : Access_Boolean;
  608.       --  Pointer to a flag indicating that this task's body has been
  609.       --  elaborated. The flag is created and managed by the
  610.       --  compiler-generated code.
  611.       --  Protection: The field itself is only accessed by Activator. The flag
  612.       --  that it points to is updated by Master and read by Activator; access
  613.       --  is assumed to be atomic.
  614.  
  615.       Stage : Task_Stage;
  616.       --  The general stage of the task in it's life cycle.
  617.       --  Protection: Self.L.
  618.  
  619.       --  beginning of flags
  620.  
  621.       Cancel_Was_Successful : Boolean;
  622.       --  This indicates that the last attempt to cancel an entry call was
  623.       --  successful. It needs to be accurate between a call to
  624.       --  *Cancel_*_Entry_Call and the following call to Complete_*_Entry_Call.
  625.       --  These calls cannot be nested; that is, there can be no intervening
  626.       --  *Cancel_*_Entry_Call, so this single field is adequate.
  627.       --  Protection: Accessed only by Self.
  628.  
  629.       Accepting : Accepting_State;
  630.       --  The ability of this task to accept an entry call.
  631.       --  Protection: Self.L.
  632.  
  633.       Aborting : Boolean;
  634.       --  Self is in the process of aborting. While set, prevents multiple
  635.       --  abortion signals from being sent by different aborter while abortion
  636.       --  is acted upon. This is essential since an aborter which calls
  637.       --  Abort_To_Level could set the Pending_ATC_Level to yet a lower level
  638.       --  (than the current level), may be preempted and would send the
  639.       --  abortion signal when resuming execution. At this point, the abortee
  640.       --  may have completed abortion to the proper level such that the
  641.       --  signal (and resulting abortion exception) are not handled any more.
  642.       --  In other words, the flag prevents a race between multiple aborters
  643.       --  and the abortee.
  644.       --  Protection: Self.L.
  645.  
  646.       Terminate_Alternative : Boolean;
  647.       --  Task is accepting Select with Terminate Alternative.
  648.  
  649.       Interrupt_Entry : Boolean := false;
  650.       --  Indicates if one or more Interrupt Entries are attached to
  651.       --  the task. This flag is needed for cleaning up the Interrupt
  652.       --  Entry bindings.
  653.  
  654.       --  end of flags
  655.  
  656.       Entry_Calls : Entry_Call_Array;
  657.       --  An array of entry calls.
  658.       --  Protection: The elements of this array are on entry call queues
  659.       --  associated with protected objects or task entries, and are protected
  660.       --  by the protected object lock or Acceptor.L, respectively.
  661.  
  662.       Entry_Queues : Task_Entry_Queue_Array (1 .. Entry_Num);
  663.       --  An array of task entry queues.
  664.       --  Protection: Self.L. Once a task has set Self.Stage to Completing, it
  665.       --  has exclusive access to this field.
  666.  
  667.       Direct_Attributes : Direct_Attribute_Array;
  668.       --  for task attributes that have same size as Address
  669.       Is_Defined : Direct_Index_Vector := 0;
  670.       --  bit I is 1 iff Direct_Attributes (I) is defined
  671.       Indirect_Attributes : Access_Address;
  672.       --  a pointer to chain of records for other attributes that
  673.       --  are not address-sized, including all tagged types.
  674.  
  675.    end record;
  676.  
  677.    type Barrier_Function_Pointer is access
  678.      function
  679.        (O : System.Address;
  680.         E : Protected_Entry_Index)
  681.         return Boolean;
  682.    --  Pointer to a function which evaluates the barrier of a protected
  683.    --  entry body. O is a pointer to the compiler-generated record
  684.    --  representing the protected object, and E is the index of the
  685.    --  entry serviced by the body.
  686.  
  687.    type Entry_Action_Pointer is access
  688.      procedure
  689.        (O : System.Address;
  690.         P : System.Address;
  691.         E : Protected_Entry_Index);
  692.    --  Pointer to a procedure which executes the sequence of statements
  693.    --  of a protected entry body. O is a pointer to the compiler-generated
  694.    --  record representing the protected object, P is a pointer to the
  695.    --  record of entry parameters, and E is the index of the
  696.    --  entry serviced by the body.
  697.  
  698.    type Entry_Body is record
  699.       Barrier : Barrier_Function_Pointer;
  700.       Action  : Entry_Action_Pointer;
  701.    end record;
  702.    --  The compiler-generated code passes objects of this type to the GNARL
  703.    --  to allow it to access the executable code of an entry body.
  704.  
  705.    type Protected_Entry_Body_Array is
  706.      array (Positive_Protected_Entry_Index range <>) of Entry_Body;
  707.    --  This is an array of the executable code for all entry bodies of
  708.    --  a protected type.
  709.  
  710.    type Protected_Entry_Body_Access is access all Protected_Entry_Body_Array;
  711.  
  712. private
  713.  
  714.    Null_Task : constant Task_ID := null;
  715.  
  716.    type Activation_Chain is new Task_ID;
  717.  
  718.    type Master_ID is new Integer;
  719.  
  720.    type Communication_Block is record
  721.       Self      : Task_ID;
  722.       Enqueued  : Boolean := False;
  723.       Cancelled : Boolean;
  724.    end record;
  725.  
  726.    type Protected_Entry_Queue_Array is
  727.         array (Protected_Entry_Index range <>) of
  728.         Entry_Queue;
  729.  
  730.    type Protection (Num_Entries : Protected_Entry_Index) is new
  731.      Ada.Finalization.Controlled
  732.    with record
  733.         L                 : Task_Primitives.Lock;
  734.         Compiler_Info     : System.Address;
  735.         Call_In_Progress  : Entry_Call_Link;
  736.         Ceiling           : System.Any_Priority;
  737.         Old_Base_Priority : System.Any_Priority;
  738.         Pending_Action    : Boolean;
  739.         Entry_Bodies      : Protected_Entry_Body_Access;
  740.         Entry_Queues      : Protected_Entry_Queue_Array (1 .. Num_Entries);
  741.    end record;
  742.  
  743.    procedure Finalize (Object : in out Protection);
  744.    --  Clean up a Protection object; in particular, finalize the associated
  745.    --  Lock object.
  746.  
  747. end System.Tasking;
  748.